package com.BlogPark.controller;

import com.BlogPark.controller.exception.Code;
import com.BlogPark.controller.result.Result;
import com.BlogPark.pojo.Article;
import com.BlogPark.service.CollectionService.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: MFM
 * @Date: 2022/8/11 - 08 - 11 - 14:55
 * @version: 1.0
 * 我的收藏 管理 响应
 */

@RestController
@RequestMapping("/MyCollection")
public class CollectionController {
    @Autowired
    private CollectionService collectionService;

    @GetMapping("/{userId}")
    public Result selectCollection(@PathVariable int userId){

        List<Article> data = collectionService.ViewCollections(userId);
        if (data.size()>0){
            return new Result(Code.GET_OK,data,"查询成功");
        }
        return new Result(Code.GET_ERR,null,"查询失败");
    }

    @DeleteMapping("/{userId}")
    public Result deleteCollection(@PathVariable int userId){

        Integer data = collectionService.deleteCollections(userId);
        if (data>0){

            return new Result(Code.DELETE_OK,data,"删除成功");
        }
        return new Result(Code.DELETE_ERR,null,"删除失败");

    }
}
